// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial

import { Header, HeaderAdapter } from "blocks/blocks.slint";
import { Images } from "images.slint";
import { Theme } from "theme.slint";
import { Menu, PageScrollView, PageContainer } from "widgets/widgets.slint";
import { MenuPage } from "pages/pages.slint";
import { Balance, Overview, Usage, UsageAdapter, Weather, About } from "pages/pages.slint";

export component MidMain {
    Rectangle {
        background: Theme.palette.background-gradient;

        VerticalLayout {
            padding-bottom: 50px;

            Header {}

            i-page-scroll-view := PageScrollView {
                vertical-stretch: 1;
                page-count: 5;

                PageContainer {
                    index: 0;
                    selected <=> i-page-scroll-view.selection;
                    selected-width: i-page-scroll-view.selected-width;
                    selected-height: i-page-scroll-view.selected-height;
                    selected-h-offset: i-page-scroll-view.selected-h-offset;
                    clicked => { i-page-scroll-view.toggle-selection(self.index, self.x); }
                    Overview {}
                }

                PageContainer {
                    index: 1;
                    selected <=> i-page-scroll-view.selection;
                    selected-width: i-page-scroll-view.selected-width;
                    selected-height: i-page-scroll-view.selected-height;
                    selected-h-offset: i-page-scroll-view.selected-h-offset;
                    clicked => { i-page-scroll-view.toggle-selection(self.index, self.x); }
                    Usage {}
                }

                PageContainer {
                    index: 2;
                    selected <=> i-page-scroll-view.selection;
                    selected-width: i-page-scroll-view.selected-width;
                    selected-height: i-page-scroll-view.selected-height;
                    selected-h-offset: i-page-scroll-view.selected-h-offset;
                    clicked => { i-page-scroll-view.toggle-selection(self.index, self.x); }
                    Balance {}
                }

                PageContainer {
                    index: 3;
                    selected <=> i-page-scroll-view.selection;
                    selected-width: i-page-scroll-view.selected-width;
                    selected-height: i-page-scroll-view.selected-height;
                    selected-h-offset: i-page-scroll-view.selected-h-offset;
                    clicked => { i-page-scroll-view.toggle-selection(self.index, self.x); }
                    Weather {}
                }

                PageContainer {
                    index: 4;
                    selected <=> i-page-scroll-view.selection;
                    selected-width: i-page-scroll-view.selected-width;
                    selected-height: i-page-scroll-view.selected-height;
                    selected-h-offset: i-page-scroll-view.selected-h-offset;
                    clicked => { i-page-scroll-view.toggle-selection(self.index, self.x); }
                    About {}
                }
            }
        }

        i-menu := Menu {
            stays-open: true;
            preferred-width: 100%;
            preferred-height: 100%;
            start-y: 35px;
            end-y: 75px;
            menu-width: root.width / 3;
            menu-height: root.height - 75px;

            i-menu-page := MenuPage {
                preferred-width: 100%;
                preferred-height: 100%;

                close => {
                    i-menu.hide();
                }
            }

            opend => {
                i-menu-page.current-index = 0;
            }
        }
    }
}
